<template>
	<view class="public-activity">
		<nav-header title="发布活动" showback="true" navBackcolor="transparent"></nav-header>
		<view class="public-activity-main">
			<view class="public-activity-main-tools">
				<view class="public-activity-main-tools-item u-flex">
					<view class="public-activity-main-tools-item-left u-flex">
						<view class="public-activity-main-tools-item-left-content">
							<view class="" style="z-index: 2;position: relative;">
								活动类型
							</view>
						</view>
					</view>
					<view class="public-activity-main-tools-item-right u-flex" @click="changeActivityType()">
						<view class="public-activity-main-tools-item-right-content">
							{{post.type==''?'请选择类型':post.type}}
						</view>
						<image src="../../static/img/arrow-right.png" mode=""></image>
					</view>
				</view>
				<view class="public-activity-main-tools-item u-flex">
					<view class="public-activity-main-tools-item-left u-flex">
						<view class="public-activity-main-tools-item-left-content">
							<view class="" style="z-index: 2;position: relative;">
								活动地址
							</view>
						</view>
					</view>
					<view class="public-activity-main-tools-item-right u-flex">
						<view class="public-activity-main-tools-item-right-content">
							{{post.address==''?'请选择地址':post.address}}
						</view>
						<image src="../../static/img/arrow-right.png" mode=""></image>
					</view>
				</view>
				<view class="public-activity-main-tools-item u-flex">
					<view class="public-activity-main-tools-item-left u-flex">
						<view class="public-activity-main-tools-item-left-content">
							<view class="" style="z-index: 2;position: relative;">
								开始时间
							</view>
						</view>
					</view>
					<view class="public-activity-main-tools-item-right u-flex" @click="changeStartTime()">
						<view class="public-activity-main-tools-item-right-content">
							{{post.start_time==''?'请选择':post.start_time}}
						</view>
						<image src="../../static/img/arrow-right.png" mode=""></image>
					</view>
				</view>
				<view class="public-activity-main-tools-item u-flex">
					<view class="public-activity-main-tools-item-left u-flex">
						<view class="public-activity-main-tools-item-left-content">
							<view class="" style="z-index: 2;position: relative;">
								结束时间
							</view>
						</view>
					</view>
					<view class="public-activity-main-tools-item-right u-flex" @click="changeEndTime()">
						<view class="public-activity-main-tools-item-right-content">
							{{post.end_time==''?'请选择':post.end_time}}
						</view>
						<image src="../../static/img/arrow-right.png" mode=""></image>
					</view>
				</view>
				<view class="public-activity-main-tools-item u-flex">
					<view class="public-activity-main-tools-item-left u-flex">
						<view class="public-activity-main-tools-item-left-content">
							<view class="" style="z-index: 2;position: relative;">
								活动费用
							</view>
						</view>
					</view>
					<view class="public-activity-main-tools-item-right u-flex">
						<view class="public-activity-main-tools-item-right-content">
							<input type="text" v-model="post.money" style="text-align: right;padding-right: 52rpx;" />
						</view>
						<!-- <image src="../../static/img/arrow-right.png" mode=""></image> -->
					</view>
				</view>
				<view class="public-activity-main-tools-item u-flex">
					<view class="public-activity-main-tools-item-left u-flex">
						<view class="public-activity-main-tools-item-left-content">
							<view class="" style="z-index: 2;position: relative;">
								活动群组
							</view>
						</view>
					</view>
					<view class="public-activity-main-tools-item-right u-flex" @click="changeActivityTeam()">
						<view class="public-activity-main-tools-item-right-content">
							{{post.group==''?'请选择群组':post.group}}
						</view>
						<image src="../../static/img/arrow-right.png" mode=""></image>
					</view>
				</view>
				<view class="public-activity-main-tools-item u-flex">
					<view class="public-activity-main-tools-item-left u-flex" style="width: 100%;">
						<input type="text" v-model="post.title" placeholder="请输入活动标题"
							style="font-size: 32rpx;color: #8A9199;width: 100%;" />
					</view>
					<view class="public-activity-main-tools-item-right u-flex">
					</view>
				</view>
			</view>
			<view class="public-activity-main-input">
				<textarea v-model="post.content" placeholder="请输入活动内容" maxlength="200" />
				<view class="public-activity-main-input-max">
					{{post.content.length}}/200
				</view>
			</view>
			<view class="public-activity-main-pic u-flex">
				<view class="public-activity-main-pic-item">
					<image :src="item" v-for="(item,index) in post.images"
						style="height: 136rpx;width: 136rpx;margin-right: 18rpx;border-radius: 18rpx;" mode=""></image>
					<image src="../../static/img/publish/pic.png" style="height: 136rpx;width: 136rpx;" mode=""></image>
				</view>
			</view>
			<view class="public-activity-main-btn" @click="postFun()">
				<view class="public-btn" :class="allowPost?'public-btn-color':''">
					发布
				</view>
			</view>
		</view>
		<u-picker mode="selector" v-model="showActivityTypeList" :default-selector="[0]" :range="typeList"
			@confirm="clickActivityType()"></u-picker>
		<u-picker mode="time" v-model="showStartTime" :default-selector="[0]" :range="typeList" :params="timeSetting"
			@confirm="clickStartTime()"></u-picker>
		<u-picker mode="time" v-model="showEndTime" :default-selector="[0]" :range="typeList" :params="timeSetting"
			@confirm="clickEndTime()">
		</u-picker>
		<u-picker mode="selector" v-model="showActivityPrice" :default-selector="[0]" :range="priceList"
			@confirm="clickActivityPrice()"></u-picker>
		<u-picker mode="selector" v-model="showActivityTeam" :default-selector="[0]" :range="teamList"
			@confirm="clickActivityTeam()"></u-picker>
	</view>
</template>

<script>
	//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
	import navHeader from '../../components/nav-header/nav-header.vue'
	export default {
		// 组件名称
		name: 'demo',
		// 组件参数 接收来自父组件的数据
		props: {},
		// 局部注册的组件,import引入的组件需要注入到对象中才能使用
		components: {
			navHeader
		},
		// 组件状态值
		data() {
			return {
				showActivityTypeList: false,
				showStartTime: false,
				showEndTime: false,
				showActivityPrice: false,
				showActivityTeam: false,
				timeSetting: {
					year: true,
					month: true,
					day: true,
					hour: true,
					minute: true,
				},
				text: "",
				typeList: [],
				priceList: [],
				teamList: [],
				post: {
					type: "",
					start_time: "",
					end_time: "",
					money: "",
					title: "",
					group: "10",
					content: "",
					address: "临沂市河东区沂蒙云谷",
					longitude: "118.36353",
					latitude: "35.11067",
					images: ["https://picx.zhimg.com/80/v2-07a5d59b01f655ff15d62376e97ef2e2_400x224.webp?source=1940ef5c"]
				},
				allowPost: false
			}
		},
		// 计算属性
		computed: {},
		// 侦听器
		watch: {
			'post': {
				handler() {
					this.allowPost = this.canPost()
					console.log(this.allowPost)
				},
				deep: true
			},
		},
		// 组件方法
		methods: {
			getActivityTags() {
				let that = this;
				that.$http('config.commond', {
					code: 'ActivityType'
				}, '').then(res => {
					this.typeList = res.data
				});
			},
			changeActivityType() {
				this.showActivityTypeList = !this.showActivityTypeList
			},
			changeStartTime() {
				this.showStartTime = !this.showStartTime
			},
			changeEndTime() {
				this.showEndTime = !this.showEndTime
			},
			// changeActivityPrice() {
			// 	this.showActivityPrice = !this.showActivityPrice
			// },
			changeActivityTeam() {
				this.showActivityTeam = !this.showActivityTeam
			},
			clickActivityType(e) {
				this.post.type = this.typeList[e]
			},
			clickStartTime(e) {
				this.post.start_time = e.year + '/' + e.month + '/' + e.day + ' ' + e.hour + ':' + e.minute
			},
			clickEndTime(e) {
				this.post.end_time = e.year + '/' + e.month + '/' + e.day + ' ' + e.hour + ':' + e.minute
			},
			// clickActivityPrice(e) {
			// 	this.post.money = this.priceList[e]
			// },
			clickActivityTeam(e) {
				this.post.group = this.teamList[e]
			},
			canPost() {
				if (this.post.type == '') {
					return '请选择活动类型'
				}
				if (this.post.latitude == '' || this.post.longitude == '') {
					return '请选择活动地址'
				}
				if (this.post.start_time == '') {
					return '请选择开始时间'
				}
				if (this.post.end_time == '') {
					return '请选择结束时间'
				}
				if (this.post.money == '') {
					return '请输入活动费用'
				}
				if (this.post.group == '') {
					return '请选择活动群组'
				}
				if (this.post.title == '') {
					return '请输入活动标题'
				}
				if (this.post.content == '') {
					return '请输入活动内容'
				}

				return true
			},
			postFun() {
				let that = this;
				if (that.canPost() == true) {
					let item = {}
					item = JSON.parse(JSON.stringify(that.post))
					console.log(item)
					that.$http('public.pushActivity', item, '').then(res => {
						uni.showToast({
							title: res.info,
							icon: 'none',
							position: 'top'
						});
						this.$Router.back()
					});
				} else {
					uni.showToast({
						title: that.canPost(),
						icon: 'none',
						position: 'top'
					});
				}
			}
		},
		// 以下是生命周期钩子   注：没用到的钩子请自行删除
		/**
		 * 在实例初始化之后，组件属性计算之前，如data属性等
		 */
		beforeCreate() {},
		/**
		 * 组件实例创建完成，属性已绑定，但DOM还未生成，$ el属性还不存在
		 */
		created() {},
		/**
		 * 在挂载开始之前被调用：相关的 render 函数首次被调用。
		 */
		beforeMount() {},
		/**
		 * el 被新创建的 vm.$ el 替换，并挂载到实例上去之后调用该钩子。
		 * 如果 root 实例挂载了一个文档内元素，当 mounted 被调用时 vm.$ el 也在文档内。
		 */
		mounted() {
			this.getActivityTags()
		},
		/**
		 * 数据更新时调用，发生在虚拟 DOM 重新渲染和打补丁之前。
		 * 你可以在这个钩子中进一步地更改状态，这不会触发附加的重渲染过程。
		 */
		beforeUpdate() {},
		/**
		 * 由于数据更改导致的虚拟 DOM 重新渲染和打补丁，在这之后会调用该钩子。
		 * 当这个钩子被调用时，组件 DOM 已经更新，所以你现在可以执行依赖于 DOM 的操作。
		 */
		updated() {},
		/**
		 * keep-alive 组件激活时调用。 仅针对keep-alive 组件有效
		 */
		activated() {},
		/**
		 * keep-alive 组件停用时调用。 仅针对keep-alive 组件有效
		 */
		deactivated() {},
		/**
		 * 实例销毁之前调用。在这一步，实例仍然完全可用。
		 */
		beforeDestroy() {},
		/**
		 * Vue 实例销毁后调用。调用后，Vue 实例指示的所有东西都会解绑定，
		 * 所有的事件监听器会被移除，所有的子实例也会被销毁。
		 */
		destroyed() {}
	}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<!--使用了scoped属性之后，父组件的style样式将不会渗透到子组件中，-->
<!--然而子组件的根节点元素会同时被设置了scoped的父css样式和设置了scoped的子css样式影响，-->
<style scoped lang="scss">
	.public-activity {
		width: 100%;
		height: 100%;
		background: linear-gradient(#F1EFFFFF 0%, #FFFFFF 20%);
		padding-top: $nav-top-height;

		&-main {
			padding: 0 32rpx;

			&-input {
				width: 100%;
				margin: 32rpx 0;
				padding-bottom: 32rpx;
				border-bottom: solid 1rpx #F5F5F5;

				&-max {
					font-size: 24rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
					color: #8A9199;
					text-align: right;
				}

				textarea {
					width: 100%;
					height: 180rpx;
					font-size: 28rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					color: #2E3033;
					line-height: 22rpx;
				}
			}

			&-tools {
				&-item {
					justify-content: space-between;
					height: 100rpx;
					border-bottom: solid 1rpx #F5F5F5FF;

					&-left {
						image {
							margin-right: 10rpx;
							width: 32rpx;
							height: 32rpx;
						}

						&-content {
							position: relative;
						}

						&-content:after {
							content: '';
							display: block;
							width: 100%;

							position: absolute;
							left: 0;
							bottom: 0;
							height: 12rpx;
							border-radius: 10rpx;
							background: #e7e5ffFF;
							z-index: 0;
						}
					}

					&-right {
						image {
							width: 40rpx;
							height: 40rpx;
							margin-left: 10rpx;
						}

						&-content {
							font-size: 28rpx;
							font-family: PingFang SC-Medium, PingFang SC;
							color: #8A9199;
						}

						.cash {
							.public-help-main-tools-item-right-content-span {
								width: 98rpx;
								height: 56rpx;
								line-height: 56rpx;
								text-align: center;
								background: #F4F4F4;
								border-radius: 30rpx;
								font-size: 28rpx;
								font-family: PingFang SC-Medium, PingFang SC;
								font-weight: 500;
								color: #8A9199;
								margin-right: 16rpx;
							}

							.act {
								background: #7266FF;
								font-size: 28rpx;
								font-family: PingFang SC-Medium, PingFang SC;
								font-weight: 500;
								color: #FCFEFF;
							}
						}
					}
				}
			}

			&-btn {
				.public-btn {
					margin: 0 auto;
					margin-top: 60rpx;
				}
			}
		}
	}
</style>
